<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 打折购买糖果的最小开销 -->
    <script>
      function minCost(cost) {
        let res = 0
        // 降序排序
        cost.sort((a, b) => b - a)
        // 前两个得买 第三个不用买
        for (let i = 0; i < cost.length; i += 3) {
          res += (cost[i] ?? 0) + (cost[i + 1] ?? 0)
        }
        return res
      }
      console.log(minCost([1, 2, 3]))
    </script>
  </body>
</html>
